<template>
  <div class="auth-container">
    <div class="auth-background">
      <div class="background-overlay"></div>
      <div class="math-formulas">
        <div class="formula formula-1">π = 3.14159...</div>
        <div class="formula formula-2">E = mc²</div>
        <div class="formula formula-3">∫₀^∞ e^(-x²) dx</div>
        <div class="formula formula-4">a² + b² = c²</div>
        <div class="formula formula-5">∑ᵢ₌₁ⁿ i = n(n+1)/2</div>
        <div class="formula formula-6">f(x) = x² + 2x + 1</div>
        <div class="formula formula-7">lim[x→∞] (1 + 1/x)^x = e</div>
        <div class="formula formula-8">√(x² + y²)</div>
        <div class="formula formula-9">sin²θ + cos²θ = 1</div>
        <div class="formula formula-10">∇f = (∂f/∂x, ∂f/∂y, ∂f/∂z)</div>
        <div class="formula formula-11">α + β = γ</div>
        <div class="formula formula-12">∞</div>
        <div class="formula formula-13">x = (-b ± √(b²-4ac))/2a</div>
        <div class="formula formula-14">∂²u/∂t² = c²∇²u</div>
        <div class="formula formula-15">P(A∩B) = P(A)P(B|A)</div>
        
        <!-- 数学符号装饰 -->
        <div class="math-symbol symbol-1">π</div>
        <div class="math-symbol symbol-2">∑</div>
        <div class="math-symbol symbol-3">∫</div>
        <div class="math-symbol symbol-4">∞</div>
        <div class="math-symbol symbol-5">√</div>
        <div class="math-symbol symbol-6">α</div>
        <div class="math-symbol symbol-7">β</div>
        <div class="math-symbol symbol-8">θ</div>
        <div class="math-symbol symbol-9">Δ</div>
        <div class="math-symbol symbol-10">∇</div>
      </div>
    </div>
    
    <div class="auth-card register-card">
      <div class="auth-header">
        <div class="logo-section">
          <div class="logo-icon">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
              <path d="M12 2C13.1 2 14 2.9 14 4C14 5.1 13.1 6 12 6C10.9 6 10 5.1 10 4C10 2.9 10.9 2 12 2ZM21 9V7L15 7.5V9M15 9.5V12.5C14.8 12.5 14.6 12.5 14.3 12.5L14.2 15L15 15L15.1 12.5C17.3 12.5 19 10.8 19 8.5V9M10 22C11.1 22 12 21.1 12 20C12 18.9 11.1 18 10 18C8.9 18 8 18.9 8 20C8 21.1 8.9 22 10 22Z"/>
            </svg>
          </div>
          <div class="logo-text">
            <h1>用户注册</h1>
            <p>创建您的考试账户</p>
          </div>
        </div>
      </div>

      <form @submit.prevent="handleRegister" class="auth-form">
        <div class="form-group">
          <label class="form-label">用户名</label>
          <div class="input-wrapper">
            <input 
              type="text" 
              v-model="registerForm.username" 
              required 
              placeholder="请输入用户名"
              class="form-input"
            >
            <div class="input-icon">
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                <path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/>
              </svg>
            </div>
          </div>
          <div class="input-hint">用户名长度需在3-20个字符之间</div>
        </div>

        <div class="form-group">
          <label class="form-label">电话号码</label>
          <div class="input-wrapper">
            <input 
              type="tel" 
              v-model="registerForm.phone" 
              required 
              placeholder="请输入电话号码"
              class="form-input"
            >
            <div class="input-icon">
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                <path d="M6.62,10.79C8.06,13.62 10.38,15.94 13.21,17.38L15.41,15.18C15.69,14.9 16.08,14.82 16.43,14.93C17.55,15.3 18.75,15.5 20,15.5A1,1 0 0,1 21,16.5V20A1,1 0 0,1 20,21A17,17 0 0,1 3,4A1,1 0 0,1 4,3H7.5A1,1 0 0,1 8.5,4C8.5,5.25 8.7,6.45 9.07,7.57C9.18,7.92 9.1,8.31 8.82,8.59L6.62,10.79Z"/>
              </svg>
            </div>
          </div>
          <div class="input-hint">请输入有效的手机号码</div>
        </div>

        <div class="form-group">
          <label class="form-label">考试年份</label>
          <div class="input-wrapper">
            <select 
              v-model="registerForm.examYear" 
              required 
              class="form-input form-select"
            >
              <option value="" disabled>请选择考试年份</option>
              <option
                v-for="year in examYears"
                :key="year"
                :value="year"
              >
                {{ year }}年
              </option>
            </select>
            <div class="input-icon">
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                <path d="M19,3H18V1H16V3H8V1H6V3H5A2,2 0 0,0 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5A2,2 0 0,0 19,3M19,19H5V8H19V19Z"/>
              </svg>
            </div>
            <div class="select-arrow">
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                <path d="M7,10L12,15L17,10H7Z"/>
              </svg>
            </div>
          </div>
          <div class="input-hint">请选择您计划参加的考试年份</div>
        </div>

        <div class="form-group">
          <label class="form-label">密码</label>
          <div class="input-wrapper">
            <input 
              :type="showPassword ? 'text' : 'password'" 
              v-model="registerForm.password" 
              required 
              placeholder="请输入密码"
              class="form-input"
              @input="checkPasswordStrength"
            >
            <div class="input-icon">
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                <path d="M18,8A2,2 0 0,1 20,10V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V10A2,2 0 0,1 6,8H7V6A5,5 0 0,1 12,1A5,5 0 0,1 17,6V8H18M12,3A3,3 0 0,0 9,6V8H15V6A3,3 0 0,0 12,3Z"/>
              </svg>
            </div>
            <button type="button" class="password-toggle" @click="showPassword = !showPassword">
              <svg v-if="showPassword" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                <path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"/>
                <line x1="1" y1="1" x2="23" y2="23"/>
              </svg>
              <svg v-else xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
                <circle cx="12" cy="12" r="3"/>
              </svg>
            </button>
          </div>
          <div class="password-strength" v-if="registerForm.password">
            <div class="strength-indicator">
              <div class="strength-bar" :class="{ 'active': passwordStrength >= 1, 'weak': passwordStrength === 1 }"></div>
              <div class="strength-bar" :class="{ 'active': passwordStrength >= 2, 'medium': passwordStrength === 2 }"></div>
              <div class="strength-bar" :class="{ 'active': passwordStrength >= 3, 'strong': passwordStrength === 3 }"></div>
            </div>
            <div class="strength-text">{{ passwordStrengthText }}</div>
          </div>
          <div class="input-hint">密码长度需在6-20个字符之间</div>
          <div class="input-hint">包含大写字母、小写字母、数字或特殊字符可增强安全性</div>
        </div>

        <div class="form-group">
          <label class="form-label">确认密码</label>
          <div class="input-wrapper">
            <input 
              :type="showConfirmPassword ? 'text' : 'password'" 
              v-model="registerForm.confirmPassword" 
              required 
              placeholder="请再次输入密码"
              class="form-input"
            >
            <div class="input-icon">
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                <path d="M12,17A2,2 0 0,0 14,15C14,13.89 13.1,13 12,13A2,2 0 0,0 10,15A2,2 0 0,0 12,17M18,8A2,2 0 0,1 20,10V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V10C4,8.89 4.9,8 6,8H7V6A5,5 0 0,1 12,1A5,5 0 0,1 17,6V8H18M12,3A3,3 0 0,0 9,6V8H15V6A3,3 0 0,0 12,3Z"/>
              </svg>
            </div>
            <button type="button" class="password-toggle" @click="showConfirmPassword = !showConfirmPassword">
              <svg v-if="showConfirmPassword" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                <path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"/>
                <line x1="1" y1="1" x2="23" y2="23"/>
              </svg>
              <svg v-else xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
                <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
                <circle cx="12" cy="12" r="3"/>
              </svg>
            </button>
          </div>
        </div>

        <button type="submit" class="auth-button primary" :disabled="isRegistering">
          <span v-if="isRegistering">注册中...</span>
          <span v-else>立即注册</span>
          <div class="button-overlay"></div>
        </button>

        <div v-if="errorMessage" class="error-message">
          <div class="error-icon">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
              <path d="M13,13H11V7H13M13,17H11V15H13M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z"/>
            </svg>
          </div>
          {{ errorMessage }}
        </div>
      </form>

      <div class="auth-footer">
        <p>已有账号？<router-link to="/login">立即登录</router-link></p>
      </div>
    </div>

    <!-- 注册成功弹窗 -->
    <div v-if="registerSuccessDialog" class="success-modal">
      <div class="modal-overlay" @click="registerSuccessDialog = false"></div>
      <div class="modal-content">
        <div class="success-icon">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
            <path d="M9,20.42L2.79,14.21L5.62,11.38L9,14.77L18.88,4.88L21.71,7.71L9,20.42Z"/>
          </svg>
        </div>
        <h3>注册成功</h3>
        <p>恭喜您，注册成功！</p>
        <div class="modal-actions">
          <button @click="goToLogin" class="auth-button primary">前往登录</button>
          <button @click="registerSuccessDialog = false" class="auth-button secondary">关闭</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, computed } from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'

const router = useRouter()

// 注册表单数据
const registerForm = reactive({
  username: '',
  phone: '',
  examYear: '',
  password: '',
  confirmPassword: ''
})

// 状态管理
const isRegistering = ref(false)
const registerSuccessDialog = ref(false)
const userId = ref(null)
const passwordStrength = ref(0)
const passwordStrengthText = ref('')
const showPassword = ref(false)
const showConfirmPassword = ref(false)
const errorMessage = ref('')

// 生成考试年份选项（近3年及未来2年）
const currentYear = new Date().getFullYear()
const examYears = computed(() => {
  const years = []
  for (let i = currentYear - 3; i <= currentYear + 2; i++) {
    years.push(i.toString())
  }
  return years
})

// 表单验证函数
const validateForm = () => {
  if (!registerForm.username) {
    errorMessage.value = '请输入用户名'
    return false
  }
  if (registerForm.username.length < 3 || registerForm.username.length > 20) {
    errorMessage.value = '用户名长度需在3-20个字符之间'
    return false
  }
  if (!registerForm.phone) {
    errorMessage.value = '请输入电话号码'
    return false
  }
  if (!/^1[3-9]\d{9}$/.test(registerForm.phone)) {
    errorMessage.value = '请输入有效的手机号码'
    return false
  }
  if (!registerForm.examYear) {
    errorMessage.value = '请选择考试年份'
    return false
  }
  if (!registerForm.password) {
    errorMessage.value = '请输入密码'
    return false
  }
  if (registerForm.password.length < 6 || registerForm.password.length > 20) {
    errorMessage.value = '密码长度需在6-20个字符之间'
    return false
  }
  if (!registerForm.confirmPassword) {
    errorMessage.value = '请确认密码'
    return false
  }
  if (registerForm.password !== registerForm.confirmPassword) {
    errorMessage.value = '两次输入的密码不一致'
    return false
  }
  if (passwordStrength.value < 1) {
    errorMessage.value = '密码强度不足，请使用更复杂的密码'
    return false
  }
  return true
}

// 检查密码强度
const checkPasswordStrength = () => {
  const password = registerForm.password
  let strength = 0
  
  if (!password) {
    passwordStrength.value = 0
    passwordStrengthText.value = ''
    return
  }
  
  // 长度评分
  if (password.length >= 8) strength += 1
  if (password.length >= 12) strength += 1
  
  // 复杂度评分
  if (/[A-Z]/.test(password)) strength += 1      // 大写字母
  if (/[a-z]/.test(password)) strength += 1      // 小写字母
  if (/[0-9]/.test(password)) strength += 1      // 数字
  if (/[^A-Za-z0-9]/.test(password)) strength += 2 // 特殊字符
  
  // 限制最高强度为3
  passwordStrength.value = Math.min(strength, 3)
  
  // 设置强度文本
  switch (passwordStrength.value) {
    case 1:
      passwordStrengthText.value = '弱（建议增强）'
      break
    case 2:
      passwordStrengthText.value = '中'
      break
    case 3:
      passwordStrengthText.value = '强'
      break
    default:
      passwordStrengthText.value = ''
  }
}

// 处理注册提交
const handleRegister = async () => {
  errorMessage.value = ''
  
  if (!validateForm()) {
    return
  }
  
  isRegistering.value = true
  
  try {
    // 创建表单数据对象
    const formData = new URLSearchParams()
    formData.append('username', registerForm.username)
    formData.append('phone', registerForm.phone)
    formData.append('examYear', registerForm.examYear.toString())
    formData.append('password', registerForm.password)

    // 发送注册请求
    const response = await axios.post('/user/register', formData, {
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    })
    
    if (response.data) {
      userId.value = response.data
      registerSuccessDialog.value = true
      
      // 重置表单
      Object.keys(registerForm).forEach(key => {
        registerForm[key] = ''
      })
      passwordStrength.value = 0
      passwordStrengthText.value = ''
    } else {
      throw new Error('注册失败，未返回用户ID')
    }
  } catch (error) {
    console.error('注册失败:', error)
    
    let errorMsg = '注册失败，请稍后重试'
    
    if (error.response) {
      if (error.response.data && error.response.data.errors) {
        const fieldErrors = error.response.data.errors
        errorMsg = Object.values(fieldErrors).join('; ')
      } else if (error.response.data && error.response.data.message) {
        errorMsg = error.response.data.message
      } else if (typeof error.response.data === 'string') {
        errorMsg = error.response.data
      }
    } else if (error.message) {
      errorMsg = error.message
    }
    
    errorMessage.value = errorMsg
  } finally {
    isRegistering.value = false
  }
}

// 跳转到登录页
const goToLogin = () => {
  registerSuccessDialog.value = false
  router.push('/login')
}
</script>

<style scoped>
.auth-container {
  min-height: 100vh;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: hidden;
}

.auth-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  z-index: -2;
}

.background-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #4e6694 0%, #3b527a 50%, #1a2f54 100%);
  opacity: 0.85;
}

.math-formulas {
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Times New Roman', serif;
}

/* 数学公式样式 */
.formula {
  position: absolute;
  color: rgba(255, 255, 255, 0.4);
  font-size: 32px;
  font-weight: 300;
  white-space: nowrap;
  pointer-events: none;
  animation: float-formula 15s ease-in-out infinite;
}

.formula-1 {
  top: 10%;
  left: 5%;
  font-size: 30px;
  animation-delay: 0s;
}

.formula-2 {
  top: 20%;
  right: 10%;
  font-size: 34px;
  animation-delay: 2s;
}

.formula-3 {
  top: 35%;
  left: 15%;
  font-size: 28px;
  animation-delay: 4s;
}

.formula-4 {
  top: 15%;
  left: 40%;
  font-size: 32px;
  animation-delay: 6s;
}

.formula-5 {
  top: 45%;
  right: 20%;
  font-size: 30px;
  animation-delay: 8s;
}

.formula-6 {
  top: 60%;
  left: 8%;
  font-size: 31px;
  animation-delay: 10s;
}

.formula-7 {
  top: 25%;
  right: 35%;
  font-size: 29px;
  animation-delay: 12s;
}

.formula-8 {
  top: 70%;
  left: 35%;
  font-size: 33px;
  animation-delay: 14s;
}

.formula-9 {
  top: 55%;
  right: 5%;
  font-size: 30px;
  animation-delay: 1s;
}

.formula-10 {
  top: 80%;
  left: 60%;
  font-size: 28px;
  animation-delay: 3s;
}

.formula-11 {
  top: 5%;
  right: 50%;
  font-size: 32px;
  animation-delay: 5s;
}

.formula-12 {
  top: 40%;
  left: 70%;
  font-size: 38px;
  animation-delay: 7s;
}

.formula-13 {
  top: 85%;
  right: 15%;
  font-size: 27px;
  animation-delay: 9s;
}

.formula-14 {
  top: 30%;
  left: 25%;
  font-size: 29px;
  animation-delay: 11s;
}

.formula-15 {
  top: 75%;
  right: 40%;
  font-size: 30px;
  animation-delay: 13s;
}

/* 数学符号样式 */
.math-symbol {
  position: absolute;
  color: rgba(255, 255, 255, 0.35);
  font-size: 80px;
  font-weight: 300;
  pointer-events: none;
  animation: float-symbol 12s ease-in-out infinite;
}

.symbol-1 {
  top: 12%;
  right: 25%;
  animation-delay: 1.5s;
}

.symbol-2 {
  top: 65%;
  left: 20%;
  animation-delay: 3.5s;
}

.symbol-3 {
  top: 35%;
  right: 8%;
  animation-delay: 5.5s;
}

.symbol-4 {
  top: 18%;
  left: 75%;
  animation-delay: 7.5s;
}

.symbol-5 {
  top: 50%;
  left: 5%;
  animation-delay: 9.5s;
}

.symbol-6 {
  top: 78%;
  right: 65%;
  animation-delay: 11.5s;
}

.symbol-7 {
  top: 8%;
  left: 60%;
  animation-delay: 2.5s;
}

.symbol-8 {
  top: 42%;
  right: 45%;
  animation-delay: 4.5s;
}

.symbol-9 {
  top: 88%;
  left: 15%;
  animation-delay: 6.5s;
}

.symbol-10 {
  top: 28%;
  left: 85%;
  animation-delay: 8.5s;
}

@keyframes float-formula {
  0% { 
    transform: translateY(0) rotate(0deg);
    opacity: 0;
  }
  15% { 
    transform: translateY(-10px) rotate(1deg);
    opacity: 0.5;
  }
  30% { 
    transform: translateY(-15px) rotate(2deg);
    opacity: 0.6;
  }
  45% { 
    transform: translateY(-8px) rotate(-1deg);
    opacity: 0.4;
  }
  60% { 
    transform: translateY(-20px) rotate(1.5deg);
    opacity: 0.55;
  }
  75% { 
    transform: translateY(-12px) rotate(-0.5deg);
    opacity: 0.3;
  }
  90% { 
    transform: translateY(-5px) rotate(0.5deg);
    opacity: 0.1;
  }
  100% { 
    transform: translateY(0) rotate(0deg);
    opacity: 0;
  }
}

@keyframes float-symbol {
  0% { 
    transform: translateY(0) rotate(0deg) scale(1);
    opacity: 0;
  }
  20% { 
    transform: translateY(-15px) rotate(3deg) scale(1.05);
    opacity: 0.4;
  }
  40% { 
    transform: translateY(-25px) rotate(5deg) scale(1.1);
    opacity: 0.5;
  }
  60% { 
    transform: translateY(-10px) rotate(-3deg) scale(0.95);
    opacity: 0.35;
  }
  80% { 
    transform: translateY(-18px) rotate(2deg) scale(1.02);
    opacity: 0.2;
  }
  95% { 
    transform: translateY(-5px) rotate(-1deg) scale(0.98);
    opacity: 0.05;
  }
  100% { 
    transform: translateY(0) rotate(0deg) scale(1);
    opacity: 0;
  }
}

.auth-card {
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
  animation: slideInUp 0.6s ease-out;
  position: relative;
  backdrop-filter: blur(10px);
  z-index: 10;
}

.register-card {
  max-width: 520px;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.auth-header {
  background: linear-gradient(135deg, #4e6694 0%, #3b527a 100%);
  padding: 30px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.auth-header::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  animation: rotate 20s linear infinite;
}

@keyframes rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.logo-section {
  position: relative;
  z-index: 1;
}

.logo-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 15px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

.logo-icon svg {
  width: 30px;
  height: 30px;
  color: white;
}

.logo-text h1 {
  color: white;
  margin: 0 0 5px 0;
  font-size: 24px;
  font-weight: 600;
}

.logo-text p {
  color: rgba(255, 255, 255, 0.8);
  margin: 0;
  font-size: 14px;
}

.auth-form {
  padding: 30px;
  position: relative;
  z-index: 5;
}

.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: #1a2f54;
  font-size: 14px;
}

.input-wrapper {
  position: relative;
  z-index: 1;
}

.form-input {
  width: 100%;
  padding: 14px 16px 14px 50px;
  border: 2px solid #e6e9ed;
  border-radius: 10px;
  font-size: 15px;
  transition: all 0.3s ease;
  background: #f8f9fa;
  position: relative;
  z-index: 2;
  box-sizing: border-box;
}

.form-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 45px;
}

.form-input:focus {
  border-color: #4e6694;
  background: white;
  box-shadow: 0 0 0 3px rgba(78, 102, 148, 0.1);
  outline: none;
}

.input-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
  transition: color 0.3s ease;
  z-index: 3;
  pointer-events: none;
}

.form-input:focus + .input-icon {
  color: #4e6694;
}

.input-icon svg {
  width: 20px;
  height: 20px;
}

.select-arrow {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
  pointer-events: none;
  z-index: 3;
}

.select-arrow svg {
  width: 20px;
  height: 20px;
}

.password-toggle {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.3s ease;
  z-index: 3;
}

.password-toggle:hover {
  color: #4e6694;
}

.password-toggle svg {
  width: 20px;
  height: 20px;
}

.input-hint {
  color: #9ca3af;
  font-size: 12px;
  margin-top: 5px;
  line-height: 1.4;
}

.password-strength {
  display: flex;
  align-items: center;
  margin-top: 8px;
  gap: 12px;
}

.strength-indicator {
  display: flex;
  gap: 4px;
  flex: 1;
}

.strength-bar {
  height: 6px;
  flex: 1;
  background-color: #e5e7eb;
  border-radius: 3px;
  transition: all 0.3s ease;
}

.strength-bar.active.weak {
  background: linear-gradient(135deg, #ef4444, #dc2626);
}

.strength-bar.active.medium {
  background: linear-gradient(135deg, #f59e0b, #d97706);
}

.strength-bar.active.strong {
  background: linear-gradient(135deg, #10b981, #059669);
}

.strength-text {
  font-size: 12px;
  color: #6b7280;
  font-weight: 500;
  white-space: nowrap;
}

.auth-button {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  margin-bottom: 20px;
}

.auth-button.primary {
  background: linear-gradient(135deg, #4e6694 0%, #3b527a 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(78, 102, 148, 0.3);
}

.auth-button.secondary {
  background: #f8f9fa;
  color: #6b7280;
  border: 2px solid #e9ecef;
}

.auth-button:hover:not(:disabled) {
  transform: translateY(-2px);
}

.auth-button.primary:hover:not(:disabled) {
  box-shadow: 0 8px 25px rgba(78, 102, 148, 0.4);
}

.auth-button.secondary:hover {
  background: #e9ecef;
  color: #495057;
}

.auth-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.button-overlay {
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s ease;
}

.auth-button:hover:not(:disabled) .button-overlay {
  left: 100%;
}

.error-message {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #fee2e2, #fecaca);
  border: 1px solid #fca5a5;
  border-radius: 8px;
  color: #dc2626;
  font-size: 14px;
  margin-bottom: 16px;
}

.error-icon svg {
  width: 16px;
  height: 16px;
}

.auth-footer {
  text-align: center;
  padding: 20px 30px 30px;
  color: #6b7280;
  font-size: 14px;
}

.auth-footer a {
  color: #4e6694;
  text-decoration: none;
  font-weight: 600;
  margin-left: 4px;
}

.auth-footer a:hover {
  text-decoration: underline;
}

/* 成功弹窗样式 */
.success-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
}

.modal-content {
  background: white;
  border-radius: 16px;
  padding: 30px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  position: relative;
  z-index: 1001;
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.success-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 20px;
  background: linear-gradient(135deg, #10b981, #059669);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: success-bounce 0.6s ease-out;
}

@keyframes success-bounce {
  0% { transform: scale(0); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.success-icon svg {
  width: 30px;
  height: 30px;
  color: white;
}

.modal-content h3 {
  color: #1a2f54;
  margin: 0 0 12px 0;
  font-size: 20px;
  font-weight: 600;
}

.modal-content p {
  color: #6b7280;
  margin: 0 0 30px 0;
  font-size: 14px;
}

.modal-actions {
  display: flex;
  gap: 12px;
}

.modal-actions .auth-button {
  margin-bottom: 0;
}

/* 响应式设计 */
@media (max-width: 600px) {
  .auth-container {
    padding: 16px;
  }
  
  .auth-card {
    max-width: 100%;
  }
  
  .register-card {
    max-width: 100%;
  }
  
  .auth-header {
    padding: 24px;
  }
  
  .auth-form {
    padding: 24px;
  }
  
  .logo-text h1 {
    font-size: 20px;
  }
  
  .formula {
    font-size: 26px;
  }
  
  .math-symbol {
    font-size: 64px;
  }
  
  .modal-actions {
    flex-direction: column;
  }
}

@media (max-width: 768px) {
  .formula {
    font-size: 28px;
  }
  
  .math-symbol {
    font-size: 72px;
  }
}
</style>